<?php
/**
 * This class represents a playlist
 *
 * @author pnikray
 */
class Playlist {
    private $tracks;
    private $artists;
    private $name;
    private $id;
    private $albums;

    /**
     * Constructor
     */
    public function Playlist(){
        $this->tracks=array();
        $this->artists=array();
        $this->albums=array();
    }

    /**
     * Adds an song to the playlist
     * @param Track $track The track
     * @param Artist $artist The artist
     * @param Album $album The album
     */
    public function addSong($track,$artist,$album){
        /*for($i=0;$i<count($this->tracks);$i++){
            if($this->tracks[$i]->id()==$track->id()){
                return;
            }
        }*/
        array_push($this->tracks,$track);
        array_push($this->artists,$artist);
        array_push($this->albums,$album);
    }

    /**
     * Returns the name of the playlist
     * @return The name
     */
    public function name(){
        return $this->name;
    }

    /**
     * Returns the id of the playlist
     * @return int The id
     */
    public function id(){
        return $this->id;
    }

    /**
     * Sets the id of the playlist
     * @param int $id The id
     */
    public function setID($id){
        if(is_int((int)$id)){
        $this->id=(int)$id;
        }
    }

    /**
     * Sets the name of the playlist
     * @param String $name of the playlist
     */
    public function setName($name){
        $this->name=$name;
    }

    /**
     * Returns all the tracks that are in this playlist
     * @return array of tracks
     */
    public function songs(){
        return $this->tracks;
    }

    /**
     * Returns an array representation of the object
     * @return array representation of the object
     */
    public function toJSON(){
        $out=array();
        $out['name']=$this->name;
        $out['id']=$this->id;
        $out['tracks']=array();
        for($i=0;$i<count($this->tracks);$i++){
            array_push($out['tracks'],$this->tracks[$i]->toJSON());
        }
        $out['artists']=array();
        for($i=0;$i<count($this->artists);$i++){
            array_push($out['artists'],$this->artists[$i]->toJSON());
        }
        $out['albums']=array();
        for($i=0;$i<count($this->albums);$i++){
            array_push($out['albums'],$this->albums[$i]->toJSON());
        }
        return $out;
    }
}
?>
